package cn.dao;

import cn.model.User;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.stereotype.Repository;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

/**
 * Created by wsx on 2017/1/5.
 */
@Repository
public class UserDao extends SpringDao{
    /**
     * 查询所有的用户
     * @return
     */
    public int login(String uemail,String upasswd) {
        String sql = "select count(*) from User where uemail = ? and upasswd = ?";
        return jdbcTemplate.queryForObject(sql,new Object[]{uemail,upasswd},Integer.class);
    }

    public int register(User user) {
        String sql = "insert into user values(?,?,?,?);";
        return jdbcTemplate.update(sql, new PreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps) throws SQLException {
                ps.setString(1,user.getUname());
                ps.setString(2,user.getUemail());
                ps.setString(3,user.getUphone());
                ps.setString(4,user.getUpasswd());
            }
        });
    }
}
